// pages/card/msg-list.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData(options)
        this.loadData()
    },
    loadData() {
        let { page = 1, total = 2, list = [], loading = false } = this.data
        if (page > total || loading) {
            return
        }
        this.setData({ loading: true })
        getApp().http.get("city/member-card/msg-list", {
            data: { page, id: this.data.id }
        }).then(res => {
            page++
            total = res.data.total
            list.push(...res.data.items)
            loading = false
            this.setData({
                page, total, list, loading
            })
            wx.stopPullDownRefresh()
        })
    },
    onPullDownRefresh() {
        this.setData({
            page: 1,
            total: 2,
            list: []
        })
        this.loadData()
    },
    onReachBottom() {
        this.loadData()
    },
    onInput(evt) {
        this.content = evt.detail.value
    },
    showInput() {
        this.setData({
            isInput: 1
        })
    },
    closeInput() {
        this.setData({
            isInput: 0
        })
        this.content = ''
    },
    submit() {
        if (!this.content) {
            return
        }
        wx.showLoading({
            title: '加载中...',
        })
        getApp().http.post("city/member-card/create-msg", {
            data: {
                card_id: this.data.id,
                content: this.content
            }
        }).then(res => {
            wx.hideLoading()
            this.setData({
                page: 1,
                total: 2,
                list: []
            })
            this.loadData()
            this.closeInput()
        })
    },

})